package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Mapper;

public interface OrderMapper {


    /**
     * 添加订单数据
     * @param orders
     * @return void
     */
    void add(Orders orders);

    /**
     * 查询属于这个状态的订单个数
     * @param status
     * @return java.lang.Integer
     */

    @Select("select count(*) from orders where status=#{status}")
    Integer OrderStatistics(Integer status);

    /**
     * 查询订单单表的数据
     * @param dto
     * @return
     */
    Page<Orders> selectOrder(OrdersPageQueryDTO dto);

    /**
     * 通过订单id查询订单信息
     * @param id
     * @return
     */
    @Select("select * from orders where id=#{id}")
    Orders selectById(Long id);

    /**
     * 更新订单状态
     * @param orders
     * @return int
     */
    int pay(Orders orders);

    /**
     * @desc TODO 通过订单号查询订单信息
     * @param orders
     * @return com.sky.entity.Orders
     */

    @Select("select * from orders where number=#{number}")
    Orders selectByNumber(Orders orders);

    /*
    接单
     */
    @Update("update orders set status=#{status} where id=#{id}")
    void update(Orders orders);
    /**
     * 拒单
     */
    @Update("update orders set status=#{status},rejection_reason=#{rejectionReason} where id=#{id}")
    void OrderRejection(Orders orders);
    /**
     *
     * 取消订单
     */
    @Update("update orders set status=#{status},cancel_reason=#{cancelReason} where id=#{id}")
    void OrderCancel(Orders orders);
    /**
     * 拒单
     * @param id
     * @return
     */
    @Select("select * from orders where id=#{id}")
    Orders getById(Long id);

    /**
     * 派送订单
     * @param orders
     */
    @Update("update orders set status=#{status} where id=#{id}")
    void delivery(Orders orders);

    /**
     * 完成订单
     * @param orders
     */
    @Update("update orders set status=#{status} where id=#{id}")
    void complete(Orders orders);

}
